title: “GEOG456_HW1” author: “Carson Mays” date: “1/28/2021” output: html_notebook
MiamiPrecip = "/Users/camays/Downloads/Spring 2021/GEOG 456/MiamiPrecip.csv"
df <- read.csv(MiamiPrecip)
head(df)
## STATION NAME DATE PRCP
## 1 USW00012839 MIAMI INTERNATIONAL AIRPORT, FL US 1/1/2020 0.00
## 2 USW00012839 MIAMI INTERNATIONAL AIRPORT, FL US 1/2/2020 0.00
## 3 USW00012839 MIAMI INTERNATIONAL AIRPORT, FL US 1/3/2020 0.00
## 4 USW00012839 MIAMI INTERNATIONAL AIRPORT, FL US 1/4/2020 0.06
## 5 USW00012839 MIAMI INTERNATIONAL AIRPORT, FL US 1/5/2020 0.00
## 6 USW00012839 MIAMI INTERNATIONAL AIRPORT, FL US 1/6/2020 0.00
df1 = df[,c(3,4)]
head(df1)
## DATE PRCP
## 1 1/1/2020 0.00
## 2 1/2/2020 0.00
## 3 1/3/2020 0.00
## 4 1/4/2020 0.06
## 5 1/5/2020 0.00
## 6 1/6/2020 0.00
df1$Day <- as.Date(as.character(df1$DATE), "%m/%d/%Y")
head(df1)
## DATE PRCP Day
## 1 1/1/2020 0.00 2020-01-01
## 2 1/2/2020 0.00 2020-01-02
## 3 1/3/2020 0.00 2020-01-03
## 4 1/4/2020 0.06 2020-01-04
## 5 1/5/2020 0.00 2020-01-05
## 6 1/6/2020 0.00 2020-01-06
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(RColorBrewer)
fig1 <- plot_ly(df1, x = ~Day, y = ~PRCP,type = "scatter") %>% layout(title="Miami Precipitation 2020")
fig1
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
nrow(df1)
## [1] 366
tt = df1[!is.na(df1$PRCP),]
nrow(tt)
## [1] 366
myColorPalette = brewer.pal(9,"Blues")
myColors = colorRampPalette(myColorPalette[5:9])
myScale = min(df1$PRCP)-1
print(myScale)
## [1] -1
print(max(df1$PRCP))
## [1] 7.4
PRCPRange = max(df1$PRCP)-(min(df1$PRCP)-1)
print(PRCPRange)
## [1] 8.4
df1$PRCPColor = myColors(PRCPRange)[df1$PRCP-myScale]
fig1 <- plot_ly(df1, x = ~Day, y = ~PRCP, main = "Miami Precipitation 2020",type = "scatter", marker = list(color=df1$PRCPColor)) %>% layout(title="Miami Precipitation 2020")
fig1
## No scatter mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
## Warning: 'scatter' objects don't have these attributes: 'main'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'meta', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'xperiod', 'yperiod', 'xperiod0', 'yperiod0', 'xperiodalignment', 'yperiodalignment', 'stackgroup', 'orientation', 'groupnorm', 'stackgaps', 'text', 'texttemplate', 'hovertext', 'mode', 'hoveron', 'hovertemplate', 'line', 'connectgaps', 'cliponaxis', 'fill', 'fillcolor', 'marker', 'selected', 'unselected', 'textposition', 'textfont', 'r', 't', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'metasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'texttemplatesrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
fig2 <- plot_ly(df1, x = ~Day, y = ~PRCP, main = "Miami Precipitation 2020",type = "bar", marker = list(color=df1$PRCPColor)) %>% layout(title="Miami Precipitation 2020")
fig2
## Warning: 'bar' objects don't have these attributes: 'main'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'meta', 'selectedpoints', 'hoverinfo', 'hoverlabel', 'stream', 'transforms', 'uirevision', 'x', 'x0', 'dx', 'y', 'y0', 'dy', 'xperiod', 'yperiod', 'xperiod0', 'yperiod0', 'xperiodalignment', 'yperiodalignment', 'text', 'texttemplate', 'hovertext', 'hovertemplate', 'textposition', 'insidetextanchor', 'textangle', 'textfont', 'insidetextfont', 'outsidetextfont', 'constraintext', 'cliponaxis', 'orientation', 'base', 'offset', 'width', 'marker', 'offsetgroup', 'alignmentgroup', 'selected', 'unselected', 'r', 't', '_deprecated', 'error_x', 'error_y', 'xcalendar', 'ycalendar', 'xaxis', 'yaxis', 'idssrc', 'customdatasrc', 'metasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'texttemplatesrc', 'hovertextsrc', 'hovertemplatesrc', 'textpositionsrc', 'basesrc', 'offsetsrc', 'widthsrc', 'rsrc', 'tsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
library(ggridges)
df1$Month <- format(df1$Day,"%m")
head(df1)
## DATE PRCP Day PRCPColor Month
## 1 1/1/2020 0.00 2020-01-01 #6BAED6 01
## 2 1/2/2020 0.00 2020-01-02 #6BAED6 01
## 3 1/3/2020 0.00 2020-01-03 #6BAED6 01
## 4 1/4/2020 0.06 2020-01-04 #6BAED6 01
## 5 1/5/2020 0.00 2020-01-05 #6BAED6 01
## 6 1/6/2020 0.00 2020-01-06 #6BAED6 01
ggplot(df1, aes(x = PRCP, y = Month, fill = ..x..)) +
geom_density_ridges_gradient(scale = 3, rel_min_height = 0.01) +
labs(title = 'Monthly Precipitation in Miami') +
scale_fill_gradientn(colors = colorRampPalette(brewer.pal(9,"Blues")[5:9])(PRCPRange))
## Picking joint bandwidth of 0.0886